<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <!-- 自动获取焦点 -->
        <input type="text" name="" id="">
        <!-- autofocus有可能无效，目前原因不明，猜测和vue生命周期有关 -->
        <!-- <input type="text" name="" id="" :autofocus='autofocus'> -->
        <input type="text" name="" id="" v-focus>
    </div>
    <script src="js/vue.js"></script>
    <script>
        Vue.directive('focus', {
            inserted: function(el, binding) {
                el.focus();
            }
        });
        const vue = new Vue({
            el: '#app',
            data: {
                autofocus: true
            }
        });
    </script>
</body>

</html>